<!DOCTYPE HTML>
<?php 
    session_start(); 
    
    if(isset($_SESSION['id'], $_SESSION['vorname'], $_SESSION['name'])){
        $id = $_SESSION['id'];
        $vorname = $_SESSION['vorname'];
        $name = $_SESSION['name'];
    }
?>

<?php if(isset($_SESSION['id'], $_SESSION['vorname'], $_SESSION['name'])) : ?>
    <?php if ($_SESSION['id']=="root") : ?> 
<html>

<head>
<title>Admin</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<link href='./images/favicon.ico' rel='shortcut icon' type='image/png'>
<link rel="stylesheet" type="text/css" href="./css/index.css">
</head>


<body id="fondo">
<div id="cuerpo">
<fieldset style="width: 1000px; color: #FFF;";>
    <?php
        include 'header.php';
    ?>

<form name="table_select" method='POST' action="table_data.php">
<table id='admin' border="0" cellspacing=1 cellpadding=2 style="font-size: 8pt"><tr>
<td><font face="verdana"><b>Select a table to administrate</b></font></td>
<td><select name='tabla'>
<?php
$nombre_bd = 'web_db';

if (!mysql_connect('localhost', 'root', '')) {
    echo 'No se pudo conectar a mysql';
    exit;
}

$sql = "SHOW TABLES FROM $nombre_bd";
$resultado = mysql_query($sql);

if (!$resultado) {
    echo "Error de BD, no se han podido listar las tablas\n";
    echo 'Error MySQL: ' . mysql_error();
    exit;
}

while ($fila = mysql_fetch_row($resultado)) {
    echo "<option value='{$fila[0]}'> {$fila[0]}</option>";
}

mysql_free_result($resultado);


?>
</select></b></font></td>
</tr>
<tr>
	<td></td><td><input type="submit" value="Go"></input></td>
</tr>
</table>
</form>

<?php
    include 'footer.php';
?>
</fieldset>
</div>
</body>
<?php else : 
    header("location:index.php");?>
<?php endif; ?>
<?php else : 
    header("location:index.php");?>
<?php endif; ?>